<!--
 * @Descripttion: (产品追溯)
 * @Author: (admin)
 * @Date: (2025-01-21)
-->
<template>
    <div style="flex: 1;display: flex;flex-direction: column;overflow: hidden;">
      <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
        <el-form-item label="产品二维码" prop="fixtureId" >
            <el-input :input-style="{ width: '300px'}" v-model="queryParams.fixtureId" placeholder="请输入产品二维码" clearable @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
          <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 工具区域 -->
      <el-row :gutter="15" class="mb10">
        <el-col :span="1.5">
          <!-- <el-button type="primary" v-hasPermi="['cksfixtureinfo:add']" plain icon="plus" @click.stop="handleAdd">
            {{ $t('btn.add') }}
          </el-button> -->
        </el-col>
        
    </el-row>
  
    <div style="display: flex;flex: 1; flex-wrap: wrap;gap: 10px;overflow-y: auto;" >

        <coverPlate class="flex-item"  />
        
        <bottomPlate class="flex-item"/>
        <finAssemble class="flex-item"/>
        <bottomPlateCoverPlate class="flex-item"/>
        <brazing class="flex-item"/>
        <agingTreatment class="flex-item"/>
        <utTesting class="flex-item"/>
        <cnc class="flex-item"/>
        <heliumTesting class="flex-item"/>
        <ccdTesting class="flex-item"/>
    </div>
      
    </div>
  </template>
  
  <script setup name="cksfixtureinfo">
  import { listCksFixtureinfo,
   addCksFixtureinfo, delCksFixtureinfo, 
   updateCksFixtureinfo,getCksFixtureinfo, resetCksFixtureinfo
   } 
  from '@/api/business/cksfixtureinfo.js'

  import  coverPlate from '@/views/business/trace/productsub/coverPlate.vue'
  import  bottomPlate from '@/views/business/trace/productsub/bottomPlate.vue'
  import  finAssemble from '@/views/business/trace/productsub/finAssemble.vue'
  import  bottomPlateCoverPlate from '@/views/business/trace/productsub/bottomPlateCoverPlate.vue'
  import  brazing from '@/views/business/trace/productsub/brazing.vue'
  import  agingTreatment from '@/views/business/trace/productsub/agingTreatment.vue'
  import  cnc from '@/views/business/trace/productsub/cnc.vue'
  import  utTesting from '@/views/business/trace/productsub/utTesting.vue'
   import  heliumTesting from '@/views/business/trace/productsub/heliumTesting.vue'
    import  ccdTesting from '@/views/business/trace/productsub/ccdTesting.vue'
  const { proxy } = getCurrentInstance()
  const ids = ref([])
  const loading = ref(false)
  const showSearch = ref(true)
  const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    sort: '',
    sortType: 'asc',
  })
  const columns = ref([
   // { visible: true, prop: 'id', label: '主键' },
    { visible: true, prop: 'fixtureId', label: '工装编号' },
    { visible: true, prop: 'shelfId', label: '架子编号' },
    { visible: true, prop: 'locationId', label: '位置编号' },
    { visible: true, prop: 'status', label: '状态' },
    { visible: true, prop: 'usageCount', label: '使用次数' },
    { visible: true, prop: 'maxUsageCount', label: '最大使用次数' },
    //{ visible: true, prop: 'nullity', label: '是否禁用' },
    //{ visible: false, prop: 'remark', label: '备注' },
    //{ visible: false, prop: 'created', label: '创建时间' },
    //{ visible: false, prop: 'isDeleted', label: '是否删除' },
  ])
  const total = ref(0)
  const dataList = ref([])
  const queryRef = ref({
    fixtureId:null
  })
  const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])
  
  
  var dictParams = [
  ]
  
  
  function getList(){
    loading.value = true
    listCksFixtureinfo(queryParams).then(res => {
      const { code, data } = res
      if (code == 200) {
        dataList.value = data.result
        total.value = data.totalNum
        loading.value = false
      }
    })
  }
  
  // 查询
  function handleQuery() {
    queryParams.pageNum = 1
    getList()
  }
  
  // 重置查询操作
  function resetQuery(){
    proxy.resetForm("queryRef")
    handleQuery()
  }
  // 自定义排序
  function sortChange(column) {
    var sort = undefined
    var sortType = undefined
  
    if (column.prop != null && column.order != null) {
      sort = column.prop
      sortType = column.order
  
    }
    queryParams.sort = sort
    queryParams.sortType = sortType
    handleQuery()
  }
  
  /*************** form操作 ***************/
  const formRef = ref()
  const title = ref('')
  // 操作类型 1、add 2、edit 3、view
  const opertype = ref(0)
  const open = ref(false)
  const state = reactive({
    single: true,
    multiple: true,
    form: {},
    rules: {
      fixtureId: [{ required: true, message: "夹具编号不能为空", trigger: "blur"    , type: "number"  }],
      shelfId: [{ required: true, message: "架子编号不能为空", trigger: "blur"    , type: "number"  }],
      locationId: [{ required: true, message: "位置编号不能为空", trigger: "blur"    , type: "number"  }],
      status: [{ required: true, message: "状态不能为空", trigger: "change"    , type: "number"  }],
      usageCount: [{ required: true, message: "使用次数不能为空", trigger: "blur"    , type: "number"  }],
      maxUsageCount: [{ required: true, message: "最大使用次数不能为空", trigger: "blur"    , type: "number"  }],
      nullity: [{ required: true, message: "是否禁用不能为空", trigger: "change"     }],
    
      created: [{ required: true, message: "创建时间不能为空", trigger: "blur"     }],
      isDeleted: [{ required: true, message: "是否删除不能为空", trigger: "blur"     }],
    },
    options: {
      // 状态 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
  statusOptions: [],
    }
  })
  
  const { form, rules, options, single, multiple } = toRefs(state)
  
  // 关闭dialog
  function cancel(){
    open.value = false
    reset()
  }
  
  // 重置表单
  function reset() {
    form.value = {
      id: null,
      fixtureId: null,
      shelfId: null,
      locationId: null,
      status: null,
      usageCount: null,
      maxUsageCount: null,
      nullity: null,
      remark: null,
      created: null,
      isDeleted: null,
    };
    proxy.resetForm("formRef")
  }
  
  
  // 添加按钮操作
  function handleAdd() {
    reset();
    open.value = true
    title.value = '添加夹具信息'
    opertype.value = 1
  }
  // 修改按钮操作
  function handleUpdate(row) {
    reset()
    const id = row.id || ids.value
    getCksFixtureinfo(id).then((res) => {
      const { code, data } = res
      if (code == 200) {
        open.value = true
        title.value = '修改夹具信息'
        opertype.value = 2
  
        form.value = {
          ...data,
        }
      }
    })
  }
  
  // 添加&修改 表单提交
  function submitForm() {
    proxy.$refs["formRef"].validate((valid) => {
      if (valid) {
  
        if (form.value.id != undefined && opertype.value === 2) {
          updateCksFixtureinfo(form.value).then((res) => {
            proxy.$modal.msgSuccess("修改成功")
            open.value = false
            getList()
          })
        } else {
          addCksFixtureinfo(form.value).then((res) => {
              proxy.$modal.msgSuccess("新增成功")
              open.value = false
              getList()
            })
        }
      }
    })
  }
  
  // 删除按钮操作
  function handleDelete(row) {
    const Ids = row.id || ids.value
  
    proxy
      .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
        confirmButtonText: proxy.$t('common.ok'),
        cancelButtonText: proxy.$t('common.cancel'),
        type: "warning",
      })
      .then(function () {
        return delCksFixtureinfo(Ids)
      })
      .then(() => {
        getList()
        proxy.$modal.msgSuccess("删除成功")
      })
  }
  
  function handleResetUsageCount(row) {
    const Ids = row.id || ids.value
    // 您正在操作的工装编号是XX,确认要对已用次数清零吗
    let msg = `您正在操作的工装编号是${row.fixtureId},确认要对已用次数清零吗`
    proxy
      .$confirm(msg, "消息", {
        confirmButtonText: proxy.$t('common.ok'),
        cancelButtonText: proxy.$t('common.cancel'),
        type: "warning",
      })
      .then(function () {
        return resetCksFixtureinfo(Ids)
      })
      .then(() => {
        getList()
        proxy.$modal.msgSuccess("操作成功")
      })
  }
  
  
  
  handleQuery()
  </script>

<style lang="scss" scoped>

:deep(.flex-item){
    width: 49%;
    flex-shrink: 0;
   // height: 180px;
   // background-color: bisque;
    //padding: 10px;
}
</style>